﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using CoreEx.Common.Data;
using LinFu.IoC.Configuration;
using LinFu.IoC.Interfaces;
using LinFu.IoC;
using CoreEx.Database.Query;
using CoreEx.MicroMapper;
namespace CoreEx.Database.Linq.Implementation
{
    [Implements(typeof(IExecutor))]
    public class Executor : IExecutor, IInitialize
    {
        private IServiceContainer _serviceContainer;

        public void Execute(ITranslateResult_old translateResult)
        {
            var dbCommand = _serviceContainer.GetService<IDbCommand>();
            translateResult.Table = dbCommand.ExecuteReader((IQueryExpression) translateResult.DbExpression).ToTable();
            
            foreach (var memberResult in translateResult.MemberResults.Values)
            {
                Execute(memberResult);
            }
        }

        public void Initialize(IServiceContainer source)
        {
            _serviceContainer = source;
        }



    }
}
